$(document).ready(function(){
	//旋转角度
	var angles;
	//可抽奖次数
	var clickNum = 3;
	//旋转次数
	var rotNum = 0;
	//中奖公告
	var notice = null;
	//转盘初始化
	var color = ["#ffbd92","#ff9d6b","rgba(0,0,0,0.5)","#d43824","white","#ff6f28"];
	var info = ["谢谢惠顾","二等奖","  三等奖","  四等奖"," 五等奖","一等奖"];
	var info1 = ['...','...','...','...','...','...']
	$('#tupBtn').bind('click',function(){
		if (clickNum >= 1) {
			//可抽奖次数减一
			clickNum = clickNum-1;
			//转盘旋转
			runCup();
			//转盘旋转过程“开始抽奖”按钮无法点击
			$('#tupBtn').attr("disabled", true);
			//旋转次数加一
			rotNum = rotNum + 1;
			//“开始抽奖”按钮无法点击恢复点击
			setTimeout(function(){
				alert(notice);
				$('#tupBtn').removeAttr("disabled", true);
			},6000);
		}
		else{
			alert("亲，抽奖次数已用光！");
		}
	});

	//转盘旋转
	function runCup(){
		probability();
		var degValue = 'rotate('+angles+'deg'+')';
		$('#myCanvas').css('-o-transform',degValue);           //Opera
		$('#myCanvas').css('-ms-transform',degValue);          //IE浏览器
		$('#myCanvas').css('-moz-transform',degValue);         //Firefox
		$('#myCanvas').css('-webkit-transform',degValue);      //Chrome和Safari
		$('#myCanvas').css('transform',degValue);
	}

	//各奖项对应的旋转角度及中奖公告内容
	function probability(){
		//获取随机数
		var num = parseInt(Math.random()*(5 - 0 + 0) + 0);
		//概率
		if ( num == 0 ) {
			angles = 2160 * rotNum + 1800;
			notice = info[0] + info1[0];
		}
		//概率
		else if ( num == 1 ) {
			angles = 2160 * rotNum + 1860;
			notice = info[5] + info1[5];
		}
		//概率
		else if ( num == 2 ) {
			angles = 2160 * rotNum + 1920;
			notice = info[4] + info1[4];
		}
		//概率
		else if ( num == 3 ) {
			angles = 2160 * rotNum + 1980;
			notice = info[3] + info1[3];
		}
		//概率
		else if ( num == 4 ) {
			angles = 2160 * rotNum + 2040;
			notice = info[2] + info1[2];
		}
		//概率
		else if ( num == 5 ) {
			angles = 2160 * rotNum + 2100;
			notice = info[1] + info1[1];
		}
	}

});
	//更改系统默认弹窗
	window.alert = function(str)
	{
		var shield = document.createElement("DIV");
		shield.id = "shield";
		shield.style.position = "absolute";
		shield.style.left = "50%";
		shield.style.top = "50%";
		shield.style.width = "280px";
		shield.style.height = "150px";
		shield.style.marginLeft = "-140px";
		shield.style.marginTop = "-110px";
		shield.style.zIndex = "25";
		var alertFram = document.createElement("DIV");
		alertFram.id="alertFram";
		alertFram.style.position = "absolute";
		alertFram.style.width = "280px";
		alertFram.style.height = "150px";
		alertFram.style.left = "50%";
		alertFram.style.top = "50%";
		alertFram.style.marginLeft = "-140px";
		alertFram.style.marginTop = "-110px";
		alertFram.style.textAlign = "center";
		alertFram.style.lineHeight = "150px";
		alertFram.style.zIndex = "300";
		strHtml = "<ul style=\"background:rgba(0,0,0,0.7);list-style:none;margin:0px;padding:0px;width:100%;border-radius:10px;\">\n";
		strHtml += " <li style=\"text-align:center;font-size:14px;padding:20px 10px; line-height:30px;color:#FFF;\">"+str+"</li>\n";
		strHtml += " <li style=\"text-align:center;font-weight:bold;height:40px;line-height:40px; padding-bottom:10px;\"><input type=\"button\" value=\"确 定\" onclick=\"doOk()\" style=\"width:80px;height:30px;background:#6dd8cd;color:white;border:none;font-size:14px;line-height:30px;outline:none;border-radius:5px;\"/></li>\n";
		strHtml += "</ul>\n";
		alertFram.innerHTML = strHtml;
		document.body.appendChild(alertFram);
		document.body.appendChild(shield);
		this.doOk = function(){
			alertFram.style.display = "none";
			shield.style.display = "none";
		}
		alertFram.focus();
		document.body.onselectstart = function(){return false;};
	}
